package com.battery.controller;

import com.battery.pojo.Device;
import com.battery.pojo.Order;
import com.battery.service.DeviceService;
import com.battery.util.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/device")
@Api(tags = "设备管理相关接口")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;
    @ResponseBody
    @CrossOrigin
    @PostMapping("/lentBattery")
    @ApiOperation("租借充电宝创建订单")
    public Result lentBattery(Order order){
        return deviceService.lentBattery(order);
    }

    @PostMapping("/addDevice")
    @ApiOperation("新增设备")
    public Result addDevice(Device device) {
        return deviceService.addDevice(device);
    }

    @PutMapping("/updateDevice")
    @ApiOperation("修改设备信息")
    public Result updateDevice(Device device) {
        return deviceService.updateDevice(device);
    }

    @GetMapping("/getDeviceById/{device_id}")
    @ApiOperation("根据id查询设备信息")
    public Result getDeviceById(@PathVariable("device_id") int device_id) {
        return deviceService.getDeviceById(device_id);
    }
    @GetMapping("/popBattery/{slot}/{deviceId}")
    @ApiOperation("根据卡槽编号和设备id弹出电源")
    public Result popBattery(@PathVariable("slot") int slot, @PathVariable("deviceId") int deviceId){
        return deviceService.popBattery(slot,deviceId);
    }

}
